Contents

# load required packages
library(simpleSeg)

1 Installation

# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("SydneyBioX/simpleSeg")

2 Overview

simpleSeg provides a structured pipeline for segmentation of cellular tiff stacks and the normalization of features, priming cells for classification / clustering

3 Quick start

simpleSeg accepts an image, image list or cytoImageList as input, and generates a CytoImageList of masks as output.

# Reading in sample data
data(pancreasImages)
summary(pancreasImages)
#> [1] "CytoImageList object of length 3 with 2 metadata columns"

The minimum input required is the image/image list and the nuclei marker to be used.

4 Segmentation

4.1 Quick Started

By default, simpleSeg identifies nuclei marker expression using principal component analysis and individual nuclei via watershedding. Nuclei are dilated out by 3 pixels to capture the cytoplasm.

The user may specify the image transformation used using the transform argument.

masks <- simpleSeg(pancreasImages, 
                   transform = c("sqrt"), 
                   watershed = "distance")
display(masks[[1]])


cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1], 
                  blue = 0.03 * pancreasImages[[1]][,,2], 
                  red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)

The measureObjects function from the cytomapper package can then be used to generate a SingleCellExperement object from the images and masks

mcols(masks)$ImageNb <- c("1", "2", "3")
mcols(pancreasImages)$ImageNb <- c("1", "2", "3")

cell.sce <- measureObjects(masks, pancreasImages, img_id = "ImageNb")

4.2 Methods of watershedding

The user may specify how watershedding is to be performed. watershed = "distance" (above) performs watershedding on a distance map of the thresholded nuclei signal.

watershed = "combine" (default; below) multiplies this distance map by the raw nuclei marker signal, thus incorporating some information as to the location of the nuclei into the watershedding process.

masks <- simpleSeg(pancreasImages, 
                   nucleus = "H3",
                   transform = "asinh", 
                   watershed = "combine")
display(masks[[1]])


cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1], 
                  blue = 0.03 * pancreasImages[[1]][,,2], 
                  red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)

4.3 Methods of cell body identification

The cell body can also be identified in simpleSeg using models of varying complexity, specified with the cellBody argument.

4.3.1 Dilatation

The default and most basic is dilation (cellBody = "dilate"). The size of the dilatation in pixels may be specified with the discDize argument.

masks <- simpleSeg(pancreasImages, 
                   nucleus = "H3",
                   transform = "asinh",
                   cellBody = "dilate",
                   discSize = 3)
display(masks[[1]])


cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1], 
                  blue = 0.03 * pancreasImages[[1]][,,2], 
                  red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)

4.3.2 Disc Model

cellBody = "diskModel uses all the markers to predict the presence of dilated ‘discs’ around the nuclei. The model therefore learns which markers are typically present in the cell cytoplasm and generates a mask based on this.

masks <- simpleSeg(pancreasImages, 
                   nucleus = "H3",
                   transform = "asinh",
                   cellBody = "discModel")
display(masks[[1]])


cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1], 
                  blue = 0.03 * pancreasImages[[1]][,,2], 
                  red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)

4.3.3 Marker model

Finally the user may specify 1 or multiple dedicated cytoplasm markers to predict the cytoplasm. this can be done using cellBody = [marker name] as below.

masks <- simpleSeg(pancreasImages,
                   nucleus = "H3",
                   transform = "asinh",
                   cellBody = "CD8a")
display(masks[[1]])


cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1], 
                  blue = 0.03 * pancreasImages[[1]][,,2], 
                  red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)

5 Parallel Processing

simpleSeg also supports parallel processing, with the cores argument being used to specify how many cores should be used.

masks <- simpleSeg(pancreasImages, cores = 5)